<template>
  <p-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <p-form layout="inline" @keyup.enter.native="searchQuery">
        <p-row :gutter="24">

        </p-row>
      </p-form>
    </div>
    <!-- 查询区域-END -->
    
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <p-button @click="handleAdd" type="primary" icon="plus">新增</p-button>
      <p-button type="primary" icon="download" @click="handleExportXls('crm_客户交易物料表')">导出</p-button>
      <p-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <p-button type="primary" icon="import">导入</p-button>
      </p-upload>




       <!-- 高级查询区域 -->
       <j-super-query :fieldList="fieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <p-dropdown v-if="selectedRowKeys.length > 0">
        <p-menu slot="overlay">
          <p-menu-item key="1" @click="batchDel"><p-icon type="delete"/>删除</p-menu-item>
        </p-menu>
        <p-button style="margin-left: 8px"> 批量操作 <p-icon type="down" /></p-button>
      </p-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>

        <span style="float:right;">
          <a @click="loadData()"><p-icon type="sync" />刷新</a>
          <p-divider type="vertical" />
          <p-popover title="自定义列" trigger="click" placement="leftBottom">
            <template slot="content">
              <p-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
                <p-row>
                  <template v-for="(item,index) in defColumns">
                    <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                        <p-col :span="12"><p-checkbox :value="item.dataIndex">{{ item.title }}</p-checkbox></p-col>
                    </template>
                  </template>
                </p-row>
              </p-checkbox-group>
            </template>
            <a><p-icon type="setting" />自定义列</a>
          </p-popover>
        </span>
      </div>
      <p-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :scroll="{ x: 1300 }"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="图片不存在" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此文件</span>
          <p-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </p-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <p-divider type="vertical" />
          <p-dropdown>
            <a class="ant-dropdown-link">更多 <p-icon type="down" /></a>
            <p-menu slot="overlay">
              <p-menu-item>
                <p-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </p-popconfirm>
              </p-menu-item>
            </p-menu>
          </p-dropdown>
        </span>

      </p-table>
    </div>
    <!-- table区域-end -->

    <baCustmcode-modal ref="modalForm" @ok="modalFormOk"></baCustmcode-modal>
  </p-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import JSuperQuery from '@/components/jeecg/JSuperQuery.vue'
  import Vue from 'vue'
  import { filterObj } from '@/utils/util';
  import BaCustmcodeModal from './modules/BaCustmcodeModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'



  //高级查询modal需要参数
    const superQueryFieldList=[
            {
                value:'custno',
                text: '客户编号',
                type: 'string'
            },
            {
                value:'mcode',
                text: '物料编号',
                type: 'string'
            },
            {
                value:'mname',
                text: '物料名称',
                type: 'string'
            },
            {
                value:'sprc',
                text: '规格型号',
                type: 'string'
            },
            {
                value:'units',
                text: '单位',
                type: 'string'
            },
            {
                value:'pleadpris',
                text: '加工单价',
                type: 'double'
            },
            {
                value:'mlpris',
                text: '单套材料费用',
                type: 'double'
            },
            {
                value:'salepris',
                text: '标准价格',
                type: 'double'
            },
            {
                value:'storageno',
                text: '专用仓编号',
                type: 'string'
            },
            {
                value:'storagename',
                text: '专用仓名称',
                type: 'string'
            },
            {
                value:'cmcode',
                text: '对应客户物料编号',
                type: 'string'
            },
            {
                value:'cmname',
                text: '对应客户物料名称',
                type: 'string'
            },
            {
                value:'csprc',
                text: '对应客户物料规格',
                type: 'string'
            },
            {
                value:'remark',
                text: '备注',
                type: 'string'
            },
            {
                value:'batchno',
                text: '批号',
                type: 'string'
            },
            {
                value:'shipnum',
                text: '已销数量',
                type: 'double'
            },
            {
                value:'ncprate',
                text: '客户占有率',
                type: 'double'
            },
            {
                value:'taxid',
                text: '税别编号',
                type: 'string'
            },
            {
                value:'taxname',
                text: '税别名称',
                type: 'string'
            },
            {
                value:'taxrate',
                text: '税率(%)',
                type: 'double'
            },
            {
                value:'custname',
                text: '客户名称',
                type: 'string'
            },
            {
                value:'shortname',
                text: '客户简称',
                type: 'string'
            },
            {
                value:'mkerid',
                text: '制单人',
                type: 'string'
            },
            {
                value:'mkername',
                text: '制单人名称',
                type: 'string'
            },
            {
                value:'mkerdate',
                text: '制单日期',
                type: 'Date'
            },
            {
                value:'chkerid',
                text: '审核人',
                type: 'string'
            },
            {
                value:'chkername',
                text: '审核人名称',
                type: 'string'
            },
            {
                value:'chkerdate',
                text: '审核日期',
                type: 'Date'
            },
            {
                value:'istates',
                text: '状态',
                type: 'select',
                dictCode: 'istates_1499'
            },
            {
                value:'mysendstate',
                text: '送审状态',
                type: 'select',
                dictCode: 'mysendstate_4417'
            },
            {
                value:'mychkinfo',
                text: '审核情况',
                type: 'string'
            },
            {
                value:'ledtid',
                text: '修改人编号',
                type: 'string'
            },
            {
                value:'ledtname',
                text: '修改人名称',
                type: 'string'
            },
            {
                value:'ledtdate',
                text: '最后修改日期',
                type: 'Date'
            },
            {
                value:'xchkerid',
                text: '复核人',
                type: 'string'
            },
            {
                value:'xchkername',
                text: '复核人名称',
                type: 'string'
            },
            {
                value:'xchkdate',
                text: '复核日期',
                type: 'Date'
            },
            {
                value:'xchkstates',
                text: '复核状态',
                type: 'select',
                dictCode: 'xchkstates_3182'
            },
            {
                value:'fzjgflg',
                text: '分支机构',
                type: 'string'
            },
            {
                value:'notaxpris',
                text: '不含税单价',
                type: 'double'
            },
            {
                value:'mdraw',
                text: '图号',
                type: 'string'
            },
    ]

  export default {
    name: "BaCustmcodeList",
    mixins:[JeecgListMixin],
    components: {
      JSuperQuery,
      BaCustmcodeModal
    },
    data () {
      return {
        fieldList:superQueryFieldList,
        superQueryFlag:false,
        superQueryParams:"",
        description: 'crm_客户交易物料表管理页面',
        // 表头
        columns: [
        ],
        //列设置
        settingColumns:[],
        //列定义
        defColumns: [
          {
            title: "序号",
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            fixed: 'left',
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'客户编号',
            align:"center",
            dataIndex: 'custno',
            width:130,
            fixed: 'left'
          },
          {
            title:'物料编号',
            align:"center",
            dataIndex: 'mcode',
            width:130,
          },
          {
            title:'物料名称',
            align:"center",
            dataIndex: 'mname',
            width:130,
          },
          {
            title:'规格型号',
            align:"center",
            dataIndex: 'sprc',
            width:130,
          },
          {
            title:'单位',
            align:"center",
            dataIndex: 'units',
            width:130,
          },
          {
            title:'加工单价',
            align:"center",
            dataIndex: 'pleadpris',
            width:130,
          },
          {
            title:'单套材料费用',
            align:"center",
            dataIndex: 'mlpris',
            width:130,
          },
          {
            title:'标准价格',
            align:"center",
            dataIndex: 'salepris',
            width:130,
          },
          {
            title:'专用仓编号',
            align:"center",
            dataIndex: 'storageno',
            width:130,
          },
          {
            title:'专用仓名称',
            align:"center",
            dataIndex: 'storagename',
            width:130,
          },
          {
            title:'对应客户物料编号',
            align:"center",
            dataIndex: 'cmcode',
            width:130,
          },
          {
            title:'对应客户物料名称',
            align:"center",
            dataIndex: 'cmname',
            width:130,
          },
          {
            title:'对应客户物料规格',
            align:"center",
            dataIndex: 'csprc',
            width:130,
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'remark',
            width:130,
          },
          {
            title:'批号',
            align:"center",
            dataIndex: 'batchno',
            width:130,
          },
          {
            title:'已销数量',
            align:"center",
            dataIndex: 'shipnum',
            width:130,
          },
          {
            title:'客户占有率',
            align:"center",
            dataIndex: 'ncprate',
            width:130,
          },
          {
            title:'税别编号',
            align:"center",
            dataIndex: 'taxid',
            width:130,
          },
          {
            title:'税别名称',
            align:"center",
            dataIndex: 'taxname',
            width:130,
          },
          {
            title:'税率(%)',
            align:"center",
            dataIndex: 'taxrate',
            width:130,
          },
          {
            title:'客户名称',
            align:"center",
            dataIndex: 'custname',
            width:130,
          },
          {
            title:'客户简称',
            align:"center",
            dataIndex: 'shortname',
            width:130,
          },
          {
            title:'制单人',
            align:"center",
            dataIndex: 'mkerid',
            width:130,
          },
          {
            title:'制单人名称',
            align:"center",
            dataIndex: 'mkername',
            width:130,
          },
          {
            title:'制单日期',
            align:"center",
            dataIndex: 'mkerdate',
            width:130,
          },
          {
            title:'审核人',
            align:"center",
            dataIndex: 'chkerid',
            width:130,
          },
          {
            title:'审核人名称',
            align:"center",
            dataIndex: 'chkername',
            width:130,
          },
          {
            title:'审核日期',
            align:"center",
            dataIndex: 'chkerdate',
            width:130,
          },
          {
            title:'状态',
            align:"center",
            dataIndex: 'istates_dictText',
            width:130,
          },
          {
            title:'送审状态',
            align:"center",
            dataIndex: 'mysendstate_dictText',
            width:130,
          },
          {
            title:'审核情况',
            align:"center",
            dataIndex: 'mychkinfo',
            width:130,
          },
          {
            title:'修改人编号',
            align:"center",
            dataIndex: 'ledtid',
            width:130,
          },
          {
            title:'修改人名称',
            align:"center",
            dataIndex: 'ledtname',
            width:130,
          },
          {
            title:'最后修改日期',
            align:"center",
            dataIndex: 'ledtdate',
            width:130,
          },
          {
            title:'复核人',
            align:"center",
            dataIndex: 'xchkerid',
            width:130,
          },
          {
            title:'复核人名称',
            align:"center",
            dataIndex: 'xchkername',
            width:130,
          },
          {
            title:'复核日期',
            align:"center",
            dataIndex: 'xchkdate',
            width:130,
          },
          {
            title:'复核状态',
            align:"center",
            dataIndex: 'xchkstates_dictText',
            width:130,
          },
          {
            title:'分支机构',
            align:"center",
            dataIndex: 'fzjgflg',
            width:130,
          },
          {
            title:'不含税单价',
            align:"center",
            dataIndex: 'notaxpris',
            width:130,
          },
          {
            title:'图号',
            align:"center",
            dataIndex: 'mdraw',
            width:130,
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            width:130,
            scopedSlots: { customRender: 'action' },
            fixed: 'right'
          }
        ],
        url: {
          list: "/codedemoapi/feixuns/baCustmcode/list",
          delete: "/codedemoapi/feixuns/baCustmcode/delete",
          deleteBatch: "/codedemoapi/feixuns/baCustmcode/deleteBatch",
          exportXlsUrl: "/codedemoapi/feixuns/baCustmcode/exportXls",
          importExcelUrl: "/codedemoapi/feixuns/baCustmcode/importExcel",
        },
        dictOptions:{},
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${this.url.importExcelUrl}`;
      }
    },
    created() {
      this.initColumns();
    },

    methods: {
      initColumns(){
        //权限过滤（列权限控制时打开，修改第二个参数为授权码前缀）
        //this.defColumns = colAuthFilter(this.defColumns,'testdemo:');

        var key = this.$route.name+":colsettings";
        let colSettings= Vue.ls.get(key);
        if(colSettings==null||colSettings==undefined){
          let allSettingColumns = [];
          this.defColumns.forEach(function (item,i,array ) {
            allSettingColumns.push(item.dataIndex);
          })
          this.settingColumns = allSettingColumns;
          this.columns = this.defColumns;
        }else{
          this.settingColumns = colSettings;
          const cols = this.defColumns.filter(item => {
            if(item.key =='rowIndex'|| item.dataIndex=='action'){
              return true;
            }
            if (colSettings.includes(item.dataIndex)) {
              return true;
            }
            return false;
          })
          this.columns =  cols;
        }
      },
      //列设置更改事件
      onColSettingsChange (checkedValues) {
        var key = this.$route.name+":colsettings";
        Vue.ls.set(key, checkedValues, 7 * 24 * 60 * 60 * 1000)
        this.settingColumns = checkedValues;
        const cols = this.defColumns.filter(item => {
          if(item.key =='rowIndex'|| item.dataIndex=='action'){
            return true
          }
          if (this.settingColumns.includes(item.dataIndex)) {
            return true
          }
          return false
        })
        this.columns =  cols;
      },
        //高级查询方法
        handleSuperQuery(arg) {
            if(!arg){
                this.superQueryParams=''
                this.superQueryFlag = false
            }else{
                this.superQueryFlag = true
                this.superQueryParams=JSON.stringify(arg)
            }
            this.loadData()
        },
        // 获取查询条件
        getQueryParams() {
            let sqp = {}
            if(this.superQueryParams){
                sqp['superQueryParams']=encodeURI(this.superQueryParams)
            }
            var param = Object.assign(sqp, this.queryParam, this.isorter);
            param.field = this.getQueryField();
            param.pageNo = this.ipagination.current;
            param.pageSize = this.ipagination.pageSize;
            return filterObj(param);
        },
      initDictConfig(){
      },

    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>